package com.yupi.usercenter.exception;

import common.BaseResponse;
import common.ErrorCode;
import common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceotionHandler(BusinessException e) {
        log.error("businessExceotionHandler", e.getMessage(),e);
        return ResultUtils.error(e.getCode(),e.getMessage(), e.getDescription());
    }
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceotionHandler(RuntimeException e) {
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
    }

}
